<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:m="http://www.ol4jsf.org"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:o="http://openfaces.org/"
	template="/WEB-INF/esquema/plantillasimple.xhtml">

	<ui:define name="body">
		<h:form>
			<div align="center">
				<strong>#{messages['spatial_rule_groups.TITLE']}</strong>
				<br />
				<rich:separator lineType="solid"/>
				<br />

				<a4j:commandLink
					value="#{messages['spatial_rule_groups.new']}"
					action="#{spatialRuleGroupsHelper.newPermitRuleGroup}"
					reRender="editPanel"
					oncomplete="#{rich:component('editPanel')}.show();">
				</a4j:commandLink>

				<br />
				<br />
				<rich:dataTable id="dtSpatialRuleGroups"
					value="#{spatialRuleGroupsHelper.spatialRuleGroups}"
					var="srg"
					columnsWidth="10%,50%,30%,10%"
					width="95%">
					<rich:column>
						<f:facet name="header">
							#{messages['spatial_rule_groups.name']}
						</f:facet>
						<h:outputText value="#{srg.name}" />
					</rich:column>
					<rich:column>
						<f:facet name="header">
							#{messages['spatial_rule_groups.description']}
						</f:facet>
						<h:outputText value="#{srg.description}" />
					</rich:column>
					<rich:column>
						<f:facet name="header">
							#{messages['spatial_rule_groups.permit_type']}
						</f:facet>
						<h:outputText value="#{messages[srg.permitType.name()]}" />
					</rich:column>
					<rich:column style="text-align:center">
						<a4j:commandLink
							value="#{messages['button.edit']}"
							action="#{spatialRuleGroupsHelper.editPermitRuleGroup(srg)}"
							reRender="editPanel"
							oncomplete="#{rich:component('editPanel')}.show();">
						</a4j:commandLink>
						#{'  '}
						<a4j:commandLink
							value="#{messages['button.delete']}"
							action="#{spatialRuleGroupsHelper.deletePermitRuleGroup(srg)}"
							reRender="dtSpatialRuleGroups">
							<o:confirmation
								message="#{messages['msg.delete_record']}. #{messages['button.continue']}?"
								caption="SIGIT"
								details=""
								okButtonText="#{messages['button.ok']}"
								cancelButtonText="#{messages['button.cancel']}">
							</o:confirmation>
						</a4j:commandLink>
					</rich:column>
				</rich:dataTable>
				
			</div>
		</h:form>
		
		
		<rich:modalPanel id="editPanel" minWidth="650" minHeight="565" resizeable="false">
			<f:facet name="header">
				<h:outputText value="#{ spatialRuleGroupsHelper.adding ? messages['spatial_rule_groups.new'] : messages['spatial_rule_groups.edit'] }"/>
			</f:facet>
			
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/img/close.png" styleClass="hidelink"
						id="hideEditPanel" />
					<rich:componentControl for="editPanel" attachTo="hideEditPanel"
						operation="hide" event="onclick" />
				</h:panelGroup>
			</f:facet>
			
			<h:form id="frmEdit">
				<h:panelGroup rendered="#{spatialRuleGroupsHelper.selected != null}">
					<div align="center" style="width:100%;height:475px;overflow:auto">
						<strong>#{messages['spatial_rule_groups.data']}</strong>
						<br />
						<rich:separator lineType="solid"/>
						<br />
						<h:panelGrid columns="2" style="width:95%">
							<h:outputText value="#{messages['spatial_rule_groups.name']}" />
							<h:inputText value="#{spatialRuleGroupsHelper.selected.name}" style="width:30%" rows="2" />
		
							<h:outputText value="#{messages['spatial_rule_groups.description']}" />
							<h:inputText value="#{spatialRuleGroupsHelper.selected.description}" style="width:100%" rows="2" />
							
							<h:outputText value="#{messages['spatial_rule_groups.approval_date']}" />
							<rich:calendar value=""/>
							
							<h:outputText value="#{messages['spatial_rule_groups.permit_type']}" />
							<h:selectOneMenu value="#{spatialRuleGroupsHelper.selected.permitType}">
								<f:selectItems value="#{spatialRuleGroupsHelper.permitTypeValueList}"/>
							</h:selectOneMenu>
						</h:panelGrid>
						
						<br />
						<br />
						
						<strong>#{messages['spatial_rules.spatial_rules']}</strong>
						<br />
						<rich:separator lineType="solid"/>
						<br />
						<a4j:commandLink
							value="#{messages['button.add']}"
							reRender="addPanel"
							oncomplete="#{rich:component('addPanel')}.show()">
						</a4j:commandLink>
						<br />
						<br />
						<rich:dataTable id="dtSpatialRules" value="#{spatialRuleGroupsHelper.selectedSpatialRules}" var="sr" width="95%">
							<f:facet name="header">
								<rich:columnGroup>
									<rich:column rowspan="2">
										#{messages['spatial_rules.code']}
									</rich:column>
									
									<rich:column colspan="2">
										#{messages['spatial_rules.operand']} 1
									</rich:column>
									<rich:column rowspan="2">
										#{messages['spatial_rules.rule_operator']}
									</rich:column>
									<rich:column colspan="2">
										#{messages['spatial_rules.operand']} 2
									</rich:column>

									<rich:column rowspan="2">
										#{messages['spatial_rules.action']}
									</rich:column>
									
									<rich:column rowspan="2">
									</rich:column>

									<rich:column breakBefore="true">
										#{messages['spatial_rules.level']}
									</rich:column>
									<rich:column>
										#{messages['spatial_rules.use']}
									</rich:column>
									
									
									<rich:column>
										#{messages['spatial_rules.level']}
									</rich:column>
									<rich:column>
										#{messages['spatial_rules.use']}
									</rich:column>
								</rich:columnGroup>
							</f:facet>
							
							<rich:column>
								<h:outputText value="#{sr.code}" />
							</rich:column>
							<rich:column>
								<h:outputText value="#{sr.levelOperand1.name}" />
							</rich:column>
							<rich:column>
								<h:outputText value="#{sr.landUseOperand1.completeCode} - #{sr.landUseOperand1.name}" />
							</rich:column>
							<rich:column>
								<h:outputText value="#{messages[sr.ruleOperator.name()]}" />
							</rich:column>
							<rich:column>
								<h:outputText value="#{sr.levelOperand2.name}" />
							</rich:column>
							<rich:column>
								<h:outputText value="#{sr.landUseOperand2.completeCode} - #{sr.landUseOperand2.name}" />
							</rich:column>
							<rich:column>
								<h:outputText value="#{messages[sr.action.name()]}" />
							</rich:column>
							<rich:column>
								<a4j:commandLink
									value="#{messages['button.delete']}"
									reRender="dtSpatialRules"
									action="#{spatialRuleGroupsHelper.deleteSpatialRule(sr)}">
								</a4j:commandLink>
							</rich:column>
						</rich:dataTable>
					</div>
					<br />
					<br />
					<div align="center">
						<a4j:commandButton
							value="#{messages['button.ok']}"
							action="#{spatialRuleGroupsHelper.applyChanges}"
							reRender="dtSpatialRuleGroups"
							oncomplete="if (#{facesContext.maximumSeverity == null}) #{rich:component('editPanel')}.hide();">
						</a4j:commandButton>
						#{' '}
						<a4j:commandButton
							value="#{messages['button.cancel']}"
							ajaxSingle="true"
							oncomplete="#{rich:component('editPanel')}.hide();">
						</a4j:commandButton>
					</div>
				</h:panelGroup>
			</h:form>
		</rich:modalPanel>
		
		<rich:modalPanel id="addPanel" minWidth="650" minHeight="410" resizeable="false">
			<f:facet name="header">
				<h:outputText value="#{messages['spatial_rule_groups.add_rule']}"/>
			</f:facet>
			
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/img/close.png" styleClass="hidelink"
						id="hideAddPanel" />
					<rich:componentControl for="addPanel" attachTo="hideAddPanel"
						operation="hide" event="onclick" />
				</h:panelGroup>
			</f:facet>
			
			<h:form id="frmAdd">
				<h:panelGroup rendered="#{spatialRuleGroupsHelper.selected != null}">
					<div align="center">
						<h:selectManyListbox value="#{spatialRuleGroupsHelper.spatialRulesSelected}" size="20" style="width:100%">
							<f:selectItems value="#{spatialRuleGroupsHelper.spatialRuleSelectList}"/>
						</h:selectManyListbox>
						
						<br />
						<br />
						<rich:messages>
							
						</rich:messages>
						
						<a4j:commandButton
							value="#{messages['button.ok']}"
							action="#{spatialRuleGroupsHelper.acceptSpatialRules}"
							reRender="dtSpatialRules"
							oncomplete="if (#{facesContext.maximumSeverity == null}) #{rich:component('addPanel')}.hide();">
						</a4j:commandButton>
						#{' '}
						<a4j:commandButton
							value="#{messages['button.cancel']}"
							ajaxSingle="true"
							oncomplete="#{rich:component('addPanel')}.hide()">
						</a4j:commandButton>
					</div>
				</h:panelGroup>
			</h:form>
		</rich:modalPanel>
	</ui:define>
</ui:composition>
